package edu.neu.swc.skynet.controller;

import edu.neu.swc.skynet.book.BookInfo;
import edu.neu.swc.skynet.common.SearchParams;
import edu.neu.swc.skynet.common.TableId;
import edu.neu.swc.skynet.service.IBookService;
import edu.neu.swc.skynet.vo.PageBookShow;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <h1>书籍服务对外HTTP接口</h1>
 * restFul风格的对外接口
 */
@RestController
@Slf4j
@RequestMapping("/book")
@Api(tags = "图书微服务对外暴露HTTP接口")
public class BookController {

    private final IBookService bookService;

    public BookController(IBookService bookService) {
        this.bookService = bookService;
    }

    @PostMapping("/page-book-show")
    @ApiOperation(value = "图书展示",
            notes = "分页获取图书展示信息",
            httpMethod = "POST"
    )
    public PageBookShow getBookPageByName(@RequestBody SearchParams searchParams){
        return bookService.getBookShowByName(searchParams);
    }

    @PostMapping("/book-info")
    @ApiOperation(value = "图书信息",
            notes = "获取图书详细信息",
            httpMethod = "POST"
    )
    public List<BookInfo> getBookInfoByIds(@RequestBody TableId tableId){
        return bookService.getBookInfoById(tableId);
    }
}
